package org.dromara.iot.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.iot.domain.bo.IotXfjyryRfidBindBo;
import org.dromara.iot.domain.vo.IotXfjyryRfidBindVo;
import org.dromara.iot.domain.vo.IotXfjyryWithTagsVo;
import org.dromara.iot.service.IIotXfjyryRfidBindService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 人员与RFID标签绑定关系
 *
 * @author Luo
 * @date 2025-07-25
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/iot/xfjyryRfidBind")
public class IotXfjyryRfidBindController extends BaseController {

    private final IIotXfjyryRfidBindService iotXfjyryRfidBindService;

    /**
     * 查询人员与RFID标签绑定关系列表
     */
    @SaCheckPermission("iot:xfjyryRfidBind:list")
    @GetMapping("/list")
    public TableDataInfo<IotXfjyryRfidBindVo> list(IotXfjyryRfidBindBo bo, PageQuery pageQuery) {
        return iotXfjyryRfidBindService.queryPageList(bo, pageQuery);
    }


    /**
     * 导出人员与RFID标签绑定关系列表
     */
    @SaCheckPermission("iot:xfjyryRfidBind:export")
    @Log(title = "人员与RFID标签绑定关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(IotXfjyryRfidBindBo bo, HttpServletResponse response) {
        List<IotXfjyryRfidBindVo> list = iotXfjyryRfidBindService.queryList(bo);
        ExcelUtil.exportExcel(list, "人员与RFID标签绑定关系", IotXfjyryRfidBindVo.class, response);
    }

    /**
     * 获取人员与RFID标签绑定关系详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("iot:xfjyryRfidBind:query")
    @GetMapping("/{id}")
    public R<IotXfjyryRfidBindVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iotXfjyryRfidBindService.queryById(id));
    }

    /**
     * 新增人员与RFID标签绑定关系
     */
    @SaCheckPermission("iot:xfjyryRfidBind:add")
    @Log(title = "人员与RFID标签绑定关系", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody IotXfjyryRfidBindBo bo) {
        return toAjax(iotXfjyryRfidBindService.insertByBo(bo));
    }

    /**
     * 修改人员与RFID标签绑定关系
     */
    @SaCheckPermission("iot:xfjyryRfidBind:edit")
    @Log(title = "人员与RFID标签绑定关系", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody IotXfjyryRfidBindBo bo) {
        return toAjax(iotXfjyryRfidBindService.updateByBo(bo));
    }

    /**
     * 删除人员与RFID标签绑定关系
     *
     * @param ids 主键串
     */
    @SaCheckPermission("iot:xfjyryRfidBind:remove")
    @Log(title = "人员与RFID标签绑定关系", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iotXfjyryRfidBindService.deleteWithValidByIds(List.of(ids), true));
    }

    /**
     * 分页查询用户及对应标签信息
     */
    @SaCheckPermission("iot:xfjyryRfidBind:list")
    @GetMapping("/pageWithTags")
    public TableDataInfo<IotXfjyryWithTagsVo> pageWithTags(IotXfjyryRfidBindBo bo, PageQuery pageQuery) {
        return iotXfjyryRfidBindService.queryXfjyryWithTagsPage(bo, pageQuery);
    }
}
